<!DOCTYPE html>
<html lang="{{ @this->lang() }}">
<head>
    <include href="blocks/head.html" />
</head>
<body>
<include href="blocks/navbar.html" />
<div class="container">
    <include href="blocks/admin/tabs.html" />
    <form action="{{ @BASE }}/admin/users/save" method="post" class="form-horizontal" autocomplete="off">
        <csrf-token />
        <check if="{{ empty(@this_user) }}">
            <true>
                <legend>{{ @dict.new_user }}</legend>
            </true>
            <false>
                <legend>{{ @dict.edit_user }}</legend>
                <input type="hidden" name="user_id" value="{{ @this_user.id }}">
            </false>
        </check>
        <div class="form-group">
            <label for="username" class="col-lg-2 control-label label-sm">{{ @dict.username }}</label>
            <div class="col-lg-10">
                <input class="form-control input-sm" id="username" type="text" name="username" value="{{ @@this_user.username ?: @@POST.username | esc }}">
            </div>
        </div>
        <div class="form-group">
            <label for="email" class="col-lg-2 control-label label-sm">{{ @dict.email }}</label>
            <div class="col-lg-10">
                <input class="form-control input-sm" id="email" type="email" name="email" value="{{ @@this_user.email ?: @@POST.email | esc }}">
            </div>
        </div>
        <div class="form-group">
            <label for="name" class="col-lg-2 control-label label-sm">{{ @dict.name | esc }}</label>
            <div class="col-lg-10">
                <input class="form-control input-sm" id="name" type="text" name="name" value="{{ @@this_user.name ?: @@POST.name | esc }}">
            </div>
        </div>
        <br>
        <div class="form-group">
            <label for="password" class="col-lg-2 control-label label-sm">{{ @dict.password }}</label>
            <div class="col-lg-10">
                <input class="form-control input-sm" id="password" type="password" name="password">
            </div>
        </div>
        <div class="form-group">
            <label for="password_confirm" class="col-lg-2 control-label label-sm">{{ @dict.confirm_password }}</label>
            <div class="col-lg-10">
                <input class="form-control input-sm" id="password_confirm" type="password" name="password_confirm">
            </div>
        </div>
        <div class="form-group">
            <div class="col-lg-10 col-lg-offset-2">
                <div class="checkbox checkbox-sm">
                    <label>
                        <input type="checkbox" name="temporary_password" value="1"> {{ @dict.require_new_password }}
                    </label>
                </div>
            </div>
        </div>
        <check if="{{ @@this_user.id != @user.id }}">
            <div class="form-group">
                <label for="rank" class="col-lg-2 control-label label-sm">{{ @dict.rank }}</label>
                <div class="col-lg-10">
                    <select class="form-control input-sm" id="rank" name="rank">
                        <repeat group="{{ (@user.rank >= \Model\User::RANK_SUPER ? range(0, 5) : range(0, 4)) }}" value="{{ @rank }}">
                            <option value="{{ @rank }}" {{ (empty(@this_user) && @rank == \Model\User::RANK_USER || @@this_user.rank == @rank) ? "selected" : "" }}>{{ @dict.ranks[@rank] }} &mdash; {{ @dict.rank_permissions[@rank] }}</option>
                        </repeat>
                    </select>
                </div>
            </div>
        </check>
        <div class="form-group">
            <label for="task_color" class="col-lg-2 control-label label-sm">{{ @dict.task_color }}</label>
            <div class="col-lg-10">
                {~ if(!empty(@this_user)) @task_color = '#' . @this_user.task_color; elseif(!empty(@POST.task_color)) @task_color = @POST.task_color; ~}
                <input class="form-control input-sm" id="task_color" type="color" name="task_color" value="{{ @@task_color ?: @rand_color | esc }}" maxlength="7">
            </div>
        </div>
        <div class="form-group">
            <div class="col-lg-10 col-lg-offset-2">
                <button type="submit" class="btn btn-primary btn-sm">{{ @dict.save }}</button>
                <a href="{{ @BASE }}/admin/users" class="btn btn-default btn-sm">{{ @dict.cancel }}</a>
            </div>
        </div>
    </form>
    <include href="blocks/footer.html" />
</div>
</body>
</html>
